package com.yiqi.liebang.feature.mine.view;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.text.TextUtils;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RadioGroup;
import android.widget.TextView;

import com.baiiu.filter.ClassifyBo;
import com.bigkoo.pickerview.builder.OptionsPickerBuilder;
import com.bigkoo.pickerview.listener.OnOptionsSelectListener;
import com.bigkoo.pickerview.view.OptionsPickerView;
import com.bumptech.glide.Glide;
import com.bumptech.glide.request.FutureTarget;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.google.gson.Gson;
import com.luck.picture.lib.PictureSelector;
import com.luck.picture.lib.config.PictureConfig;
import com.luck.picture.lib.config.PictureMimeType;
import com.luck.picture.lib.entity.LocalMedia;
import com.suozhang.framework.component.recyclerview.DividerItemDecoration;
import com.suozhang.framework.framework.AM;
import com.suozhang.framework.framework.BaseActivity;
import com.suozhang.framework.utils.T;
import com.suozhang.framework.widget.EmptyTextView;
import com.yiqi.liebang.R;
import com.yiqi.liebang.common.util.DateTool;
import com.yiqi.liebang.common.util.GetJsonDataUtil;
import com.yiqi.liebang.entity.bo.EducationBo;
import com.yiqi.liebang.entity.bo.JsonBean;
import com.yiqi.liebang.entity.bo.UserCardBo;
import com.yiqi.liebang.entity.bo.WorkBo;
import com.yiqi.liebang.entity.enums.CertificateImage;
import com.yiqi.liebang.entity.enums.CertificationStauts;
import com.yiqi.liebang.feature.home.view.ClassifyActivity;
import com.yiqi.liebang.feature.mine.contract.CertificationContract;
import com.yiqi.liebang.feature.mine.dependencies.certification.CertificationPresenterModule;
import com.yiqi.liebang.feature.mine.dependencies.certification.DaggerCertificationComponent;
import com.yiqi.liebang.feature.mine.view.adapter.DocumentEduAdapter;
import com.yiqi.liebang.feature.mine.view.adapter.WorkEditAdapter;
import com.yiqi.liebang.feature.mine.view.adapter.edit.EduInfoAdpter;
import com.yiqi.liebang.feature.mine.view.adapter.edit.WorkInfoAdpter;
import com.yiqi.liebang.feature.setting.view.ImageActivity;
import com.yiqi.liebang.framework.DataServer;

import org.json.JSONArray;

import java.io.File;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutionException;

import javax.inject.Inject;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

import static com.yiqi.liebang.common.util.DateTool.DEFAULT_SDF;

public class AllCertificationActivity extends BaseActivity implements CertificationContract.View, RadioGroup.OnCheckedChangeListener, Toolbar.OnMenuItemClickListener {

    @Inject
    CertificationContract.Presenter mPresenter;


    @BindView(R.id.toolbar)
    Toolbar mToolbar;
    @BindView(R.id.rg_ceritifcation)
    RadioGroup mRgCeritifcation;
    @BindView(R.id.view_basic)
    LinearLayout mViewBasic;
    @BindView(R.id.view_career)
    LinearLayout mViewCareer;
    @BindView(R.id.view_education)
    LinearLayout mViewEducation;
    @BindView(R.id.iv_user_head)
    ImageView mIvUserHead;
    @BindView(R.id.edt_user_name)
    EditText mEdtUserName;

    @BindView(R.id.iv_user_card)
    ImageView mIvUserCard;
    @BindView(R.id.edt_user_industry)
    EditText mEdtUserIndustry;
    @BindView(R.id.tv_user_biaoqian)
    TextView mTvUserBiaoqian;
    @BindView(R.id.tv_user_city)
    TextView mTvUserCity;
    @BindView(R.id.tv_user_address)
    EditText mTvUserAddress;
    @BindView(R.id.tv_user_mobile)
    TextView mTvUserMobile;
    @BindView(R.id.tv_user_email)
    EditText mTvUserEmail;
    @BindView(R.id.tv_user_wechat)
    EditText mTvUserWechat;
    @BindView(R.id.tv_user_card_number)
    EditText mTvUserCardNumber;
    @BindView(R.id.iv_work_company_logo)
    ImageView mIvWorkCompanyLogo;
    @BindView(R.id.iv_work_company_name)
    TextView mTvWorkCompanyName;
    @BindView(R.id.iv_work_company_date)
    TextView mTvWorkCompanyDate;
    @BindView(R.id.tv_work_company_stauts)
    TextView mTvWorkCompanyStauts;

    @BindView(R.id.iv_work_company_stauts)
    ImageView mIvWorkCompanyStauts;
    @BindView(R.id.tv_edu_name)
    TextView mTvEduName;
    @BindView(R.id.tv_edu_date)
    TextView mTvEduDate;

    @BindView(R.id.iv_edu_stauts)
    ImageView mIvEduStauts;
    @BindView(R.id.tv_edu_stauts)
    TextView mTvEduStauts;
    @BindView(R.id.rv_work_list)
    RecyclerView mRvWorkList;
    @BindView(R.id.view_upload_work)
    LinearLayout mViewUploadWork;
    @BindView(R.id.view_upload_edu)
    LinearLayout mViewUploadEdu;
    @BindView(R.id.rv_edu_list)
    RecyclerView mRvEduList;
    @BindView(R.id.rv_work_list_ago)
    RecyclerView mRvWorkListAgo;
    @BindView(R.id.rv_education_list_ago)
    RecyclerView mRvEducationListAgo;
    @BindView(R.id.btn_update_ziliao)
    TextView mBtnUpdateZiliao;

    @BindView(R.id.btn_update_ziliao_edu)
    TextView mBtnUpdateZiliaoEdu;
    @BindView(R.id.tv_work_update_time)
    TextView mTvWorkUpdateTime;
    @BindView(R.id.tv_work_update_time_edu)
    TextView mTvEduUpdateTime;
    @BindView(R.id.btn_upload_work_images)
    TextView mBtnUploadWorkImages;
    @BindView(R.id.view_stauts)
    LinearLayout mViewStauts;
    @BindView(R.id.btn_upload_edu_images)
    TextView mBtnUploadEduImages;
    @BindView(R.id.view_stauts_EDU)
    LinearLayout mViewStautsEDU;


    private String mHeadUri, mCardUri;
    private int mType = 1;
    private String mLabelsId = "";

    private List<LocalMedia> selectList;

    private List<JsonBean> options1Items = new ArrayList<>();
    private List<List<String>> options2Items = new ArrayList<>();
    private List<List<List<String>>> options3Items = new ArrayList<>();
    private Thread thread;
    private static final int MSG_LOAD_DATA = 0x0001;
    private static final int MSG_LOAD_SUCCESS = 0x0002;
    private static final int MSG_LOAD_FAILED = 0x0003;

    private boolean isLoaded = false;
    ArrayList<ClassifyBo> mLabelList = new ArrayList<>();

    private String mWorkId, mEduId = "";
    private DocumentEduAdapter documentEduAdapter;

    List<WorkBo> mWorkBos;
    List<EducationBo> mEducationBos;

    private int mCountSize = 0;
    private UserCardBo mUserBasic;

    @Override
    protected int attachLayoutRes() {
        return R.layout.activity_all_certification;
    }

    @Override
    protected void initInjector() {
        DaggerCertificationComponent.builder().certificationPresenterModule(new CertificationPresenterModule(this)).build().inject(this);
    }

    @Override
    protected void onStart() {
        super.onStart();

        mPresenter.getWorkList();
        mPresenter.getEduList();
    }

    @Override
    protected void initView() {
        mToolbar.inflateMenu(R.menu.menu_certification);
        initToolBar(mToolbar, "认证", true, true);
        mRgCeritifcation.check(R.id.rb_ceritifcation_basic);
        mPresenter.getUserSaveData();

    }


    @SuppressLint("HandlerLeak")
    private Handler mHandler = new Handler() {
        public void handleMessage(Message msg) {
            switch (msg.what) {
                case MSG_LOAD_DATA:
                    if (thread == null) {//如果已创建就不再重新创建子线程了
//                        Toast.makeText(EditOtherActivity.this, "Begin Parse Data", Toast.LENGTH_SHORT).show();
                        thread = new Thread(new Runnable() {
                            @Override
                            public void run() {
                                // 子线程中解析省市区数据
                                initJsonData();
                            }
                        });
                        thread.start();
                    }
                    break;

                case MSG_LOAD_SUCCESS:
                    isLoaded = true;
                    break;

                case MSG_LOAD_FAILED:
                    T.showShort("Parse Failed");
                    finish();
                    break;
            }
        }
    };


    @Override
    protected void initData() {
        mRvWorkListAgo.setLayoutManager(new LinearLayoutManager(this));
        mRvWorkListAgo.addItemDecoration(new DividerItemDecoration(DividerItemDecoration.VERTICAL).setHeight(2));

        mRvEduList.setLayoutManager(new LinearLayoutManager(this));
        mRvEduList.addItemDecoration(new DividerItemDecoration(DividerItemDecoration.VERTICAL).setHeight(2));

        mRvEducationListAgo.setLayoutManager(new LinearLayoutManager(this));
        mRvEducationListAgo.addItemDecoration(new DividerItemDecoration(DividerItemDecoration.VERTICAL).setHeight(2));

        mHandler.sendEmptyMessage(MSG_LOAD_DATA);
    }

    @Override
    protected void initEvent() {
        mRgCeritifcation.setOnCheckedChangeListener(this);
        mToolbar.setOnMenuItemClickListener(this);
    }

    @Override
    public void onCheckedChanged(RadioGroup group, int checkedId) {
        switch (checkedId) {
            case R.id.rb_ceritifcation_basic:
                mType = 1;
                mViewBasic.setVisibility(View.VISIBLE);
                mViewCareer.setVisibility(View.GONE);
                mViewEducation.setVisibility(View.GONE);
                mPresenter.getUserSaveData();
                break;
            case R.id.rb_ceritifcation_career:
                mType = 2;
                mViewBasic.setVisibility(View.GONE);
                mViewCareer.setVisibility(View.VISIBLE);
                mViewEducation.setVisibility(View.GONE);
                mPresenter.getWorkList();

                break;
            case R.id.rb_ceritifcation_education:
                if (mWorkBos.size() > 0) {
                    for (int j = 0; j < mWorkBos.size(); j++) {
                        WorkBo workBo = mWorkBos.get(i);
                        if (workBo.getImg().size() > 0) {
                            mType = 3;
                            mViewBasic.setVisibility(View.GONE);
                            mViewCareer.setVisibility(View.GONE);
                            mViewEducation.setVisibility(View.VISIBLE);
                            mPresenter.getEduList();
                        } else {
                            mRgCeritifcation.check(R.id.rb_ceritifcation_career);
                            showMsg("请补全工作经历证明！");
                            return;
                        }
                    }
                } else {
                    mRgCeritifcation.check(R.id.rb_ceritifcation_career);
                    showMsg("请至少添加一条工作经历！");
                    return;
                }

                break;
        }
        onPrepareOptionsMenu(mToolbar.getMenu());
    }


    @Override
    public boolean onMenuItemClick(MenuItem item) {
        switch (item.getItemId()) {
            case R.id.action__commit_auth:
                if (TextUtils.isEmpty(mTvUserMobile.getText().toString()) || TextUtils.isEmpty(mTvUserCardNumber.getText().toString())) {
                    showMsg("请完善基本信息！");
                    mRgCeritifcation.check(R.id.rb_ceritifcation_basic);
                    return true;
                }
                if (mWorkBos.size() > 0) {
                    for (int j = 0; j < mWorkBos.size(); j++) {
                        WorkBo workBo = mWorkBos.get(i);
                        if (workBo.getImg().size() == 0) {
                            mRgCeritifcation.check(R.id.rb_ceritifcation_career);
                            showMsg("请补全工作经历证明！");
                            return true;
                        }
                    }
                } else {
                    mRgCeritifcation.check(R.id.rb_ceritifcation_career);
                    showMsg("请至少添加一条工作经历！");
                    return true;
                }

                if (mEducationBos != null && mEducationBos.size() > 0) {
                    for (int j = 0; j < mEducationBos.size(); j++) {
                        EducationBo workBo = mEducationBos.get(i);
                        if (workBo.getImg().size() > 0) {
                            mPresenter.toPersonalAuthentication(DataServer.dataToWorkString(mWorkBos), DataServer.dataToEduString(mEducationBos));
                        } else {
                            showMsg("请补全教育经历证明！");
                            return true;
                        }
                    }
                } else {
                    showMsg("请至少添加一条教育经历！");
                    return true;
                }
                break;
        }
        return false;
    }


    @OnClick({R.id.btn_edit_touxiang, R.id.btn_edit_biaoqian,
            R.id.btn_edit_diqu, R.id.btn_upload_card, R.id.btn_upload_work,
            R.id.btn_upload_edu, R.id.btn_update_ziliao, R.id.btn_update_ziliao_edu, R.id.btn_save_basic})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.btn_edit_touxiang:
                initGallery(PictureConfig.SINGLE);
                break;
            case R.id.btn_edit_biaoqian:
                Intent intent = new Intent(this, ClassifyActivity.class);
                intent.putExtra("isSelect", true);
                intent.putExtra("classify", mLabelList);
                startActivityForResult(intent, 6);
                break;
            case R.id.btn_edit_diqu:
                if (isLoaded) {
                    showPickerView();
                } else {
                    T.showShort("Please waiting until the data is parsed");
                }
                break;
            case R.id.btn_upload_card:
                PictureSelector.create(this)
                        .openGallery(PictureMimeType.ofImage())
                        .theme(R.style.picture_default_style1)
                        .selectionMode(PictureConfig.SINGLE)// 多选 or 单选
                        .previewImage(true)// 是否可预览图片
                        .isZoomAnim(true)// 图片列表点击 缩放效果 默认true
                        .isCamera(true)
                        .enableCrop(true)// 是否裁剪
                        .circleDimmedLayer(false)// 是否圆形裁剪 true or false
                        .compress(true)// 是否压缩
                        .hideBottomControls(false)// 是否显示uCrop工具栏，默认不显示
                        .isGif(false)// 是否显示gif图片
                        .freeStyleCropEnabled(true)// 裁剪框是否可拖拽
                        .circleDimmedLayer(false)// 是否圆形裁剪
                        .selectionMedia(selectList)// 是否传入已选图片
                        .scaleEnabled(true)
                        .forResult(000);//结果回调onActivityResult code
                break;
            case R.id.btn_upload_work:
                Intent intentWork = new Intent(this, EditWorkActivity.class);
                intentWork.putExtra("isAdd", true);
                startActivity(intentWork);
                break;
            case R.id.btn_upload_edu:
                Intent intente = new Intent(this, EditEducationActivity.class);
                intente.putExtra("isAdd", true);
                startActivity(intente);
                break;

            case R.id.btn_save_basic:
                mPresenter.uploadBasicInfo(
                        mHeadUri,
                        mEdtUserName.getText().toString(),
                        mLabelsId,
                        mEdtUserIndustry.getText().toString(),
                        mTvUserCity.getText().toString(),
                        mTvUserAddress.getText().toString(),
                        mTvUserMobile.getText().toString(),
                        mTvUserEmail.getText().toString(),
                        mTvUserWechat.getText().toString(),
                        mTvUserCardNumber.getText().toString(),
                        "0",
                        mCardUri);

                break;

        }
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode == -1) {
            switch (requestCode) {
                case PictureConfig.SINGLE:
                    // 图片选择结果回调
                    selectList = PictureSelector.obtainMultipleResult(data);
                    for (int i = 0; i < selectList.size(); i++) {
                        mHeadUri = selectList.get(i).getCutPath();
                    }
                    AM.image().bindToCircleObject(mHeadUri, mIvUserHead);

                    break;
                case 000:
                    // 图片选择结果回调
                    selectList = PictureSelector.obtainMultipleResult(data);
                    for (int i = 0; i < selectList.size(); i++) {
                        mCardUri = selectList.get(i).getCutPath();
                    }
                    if (!TextUtils.isEmpty(mCardUri)) {
                        AM.image().bind(mCardUri, mIvUserCard);
                    }
                    break;
                case 6:
                    mLabelList = data.getParcelableArrayListExtra("labels");
                    if (mLabelList != null && mLabelList.size() > 0) {
                        String lables = "";
                        mLabelsId = "";
                        for (int i = 0; i < mLabelList.size(); i++) {
                            lables += mLabelList.get(i).getClassify() + ",";
                            mLabelsId += mLabelList.get(i).getId() + ",";
                        }
                        mLabelsId = mLabelsId.substring(0, mLabelsId.length() - 1);
                        mTvUserBiaoqian.setText(lables.substring(0, lables.length() - 1));
                    } else {
                        mLabelsId = null;
                        mTvUserBiaoqian.setText("");
                    }
                    break;
            }
        }
    }


    @Override
    public void showWorkSuccess(WorkBo workBo) {
        if (mType == 2) {
            if (workBo == null) return;
            mTvWorkCompanyName.setText(workBo.getCompany());
            mTvWorkCompanyDate.setText(workBo.getBeginTime() + " - " + workBo.getEndTime() + " , " + workBo.getPosition());
            mTvWorkCompanyStauts.setText(CertificationStauts.getName(workBo.getStatus()));
            mIvWorkCompanyStauts.setImageResource(workBo.getStatus() == 1 ? R.drawable.icon_yanzheng : R.drawable.icon_weiyanzhneg);
            mTvWorkUpdateTime.setText(workBo.getImg() != null && workBo.getImg().size() > 0 ? DateTool.formatTime(workBo.getImg().get(0).getCreateTime()) : "");
            AM.image().bindToCircleObject(workBo.getComLogo(), mIvWorkCompanyLogo);
            mBtnUpdateZiliao.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent(AllCertificationActivity.this, UploadWorkActivity.class);
                    intent.putExtra("work_id", workBo.getId());
                    intent.putExtra("works_imgs", workBo);
                    intent.putExtra("isAll", true);
                    startActivity(intent);

                }
            });
            mBtnUploadWorkImages.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent(AllCertificationActivity.this, UploadWorkActivity.class);
                    intent.putExtra("work_id", workBo.getId());
                    intent.putExtra("works_imgs", workBo);
                    intent.putExtra("isAll", true);
                    startActivity(intent);
                }
            });
            mViewUploadWork.setVisibility(View.GONE);
            mRvWorkList.setLayoutManager(new GridLayoutManager(this, 4));
            WorkEditAdapter documentAdapter = new WorkEditAdapter();
            documentAdapter.bindToRecyclerView(mRvWorkList);
            if (workBo.getImg() != null && workBo.getImg().size() > 0) {
                documentAdapter.setNewData(workBo.getImg());
                documentAdapter.setOnItemChildClickListener(new BaseQuickAdapter.OnItemChildClickListener() {
                    @Override
                    public void onItemChildClick(BaseQuickAdapter adapter, View view, int position) {
                        Intent intentWork = new Intent(AllCertificationActivity.this, ImageActivity.class);
                        intentWork.putExtra("pos", position);
                        intentWork.putExtra("images", (Serializable) workBo.getImg());
                        startActivity(intentWork);
                    }
                });
                mBtnUploadWorkImages.setVisibility(View.GONE);
                mViewStauts.setVisibility(View.VISIBLE);
            } else {
                mBtnUploadWorkImages.setVisibility(View.VISIBLE);
                mViewStauts.setVisibility(View.GONE);
            }

            mViewUploadEdu.setVisibility(View.GONE);
        }

    }

    @Override
    public void showUserCardSuccess(UserCardBo s) {
        mUserBasic = s;
        if (mType == 1) {
            showUserInfo(s);
        }
    }

    @Override
    public void showEducationSuccess(EducationBo workBo) {
        if (mType == 3) {
            if (workBo == null) return;
            mTvEduUpdateTime.setText(workBo.getImg() != null && workBo.getImg().size() > 0 ? DateTool.formatTime(workBo.getImg().get(0).getCreateTime()) : "");
            mTvEduName.setText(workBo.getSchoolName());
            mTvEduDate.setText(workBo.getBeginTime() + " - " + workBo.getEndTime() + " , " + workBo.getSubjectName());
            mTvEduStauts.setText(CertificationStauts.getName(workBo.getStatus()));
            mIvEduStauts.setImageResource(workBo.getStatus() == 1 ? R.drawable.icon_yanzheng : R.drawable.icon_weiyanzhneg);

            mBtnUpdateZiliaoEdu.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent(AllCertificationActivity.this, UploadEduActivity.class);
                    intent.putExtra("edu_id", workBo.getId());
                    intent.putExtra("edu_imgs", workBo);
                    intent.putExtra("isAll", true);
                    startActivity(intent);
                }
            });

            mBtnUploadEduImages.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {

                    Intent intent = new Intent(AllCertificationActivity.this, UploadEduActivity.class);
                    intent.putExtra("edu_id", workBo.getId());
                    intent.putExtra("edu_imgs", workBo);
                    intent.putExtra("isAll", true);
                    startActivity(intent);

                }
            });

            mRvEduList.setLayoutManager(new GridLayoutManager(this, 4));
            WorkEditAdapter documentAdapter = new WorkEditAdapter();
            documentAdapter.bindToRecyclerView(mRvEduList);
            if (workBo.getImg() != null && workBo.getImg().size() > 0) {
                documentAdapter.setNewData(workBo.getImg());
                documentAdapter.setOnItemChildClickListener(new BaseQuickAdapter.OnItemChildClickListener() {
                    @Override
                    public void onItemChildClick(BaseQuickAdapter adapter, View view, int position) {
                        Intent intentWork = new Intent(AllCertificationActivity.this, ImageActivity.class);
                        intentWork.putExtra("type", CertificateImage.ZHIYE.getIndex());
                        startActivity(intentWork);
                    }
                });
                mBtnUploadEduImages.setVisibility(View.GONE);
                mViewStautsEDU.setVisibility(View.VISIBLE);
            } else {
                mBtnUploadEduImages.setVisibility(View.VISIBLE);
                mViewStautsEDU.setVisibility(View.GONE);
            }
            mViewUploadWork.setVisibility(View.GONE);
        }
    }


    int i = 0;

    @Override
    public void showAuthWorkSuccess() {
        i++;
        if (i == mCountSize) {
            Intent intents = new Intent(this, CommitSuccessActivity.class);
            intents.putExtra("date", DateTool.getCurTimeString(DEFAULT_SDF));
            startActivity(intents);
            finish();
        }
    }

    @Override
    public void showCertificationSuccess() {
        Intent intents = new Intent(this, CommitSuccessActivity.class);
        intents.putExtra("date", DateTool.getCurTimeString(DEFAULT_SDF));
        startActivity(intents);
        finish();

    }

    @Override
    public void showError(String error) {
        showMsg(error);
    }

    List<WorkBo> workAgos = new ArrayList<>();
    List<EducationBo> educationAgoBos = new ArrayList<>();

    @Override
    public void showWorkListSuccess(List<WorkBo> workBos) {
        mWorkBos = workBos;
        if (mType == 2) {

            if (workBos != null && !workBos.isEmpty()) {
                showWorkSuccess(workBos.get(0));
                mViewCareer.setVisibility(View.VISIBLE);
                mViewUploadWork.setVisibility(View.GONE);
            } else {
                mViewCareer.setVisibility(View.GONE);
                mViewUploadWork.setVisibility(View.VISIBLE);
            }

            WorkInfoAdpter workListAdapter = new WorkInfoAdpter();
            EmptyTextView emptyTextView = new EmptyTextView(mRvWorkListAgo);
            workListAdapter.bindToRecyclerView(mRvWorkListAgo);

            if (workBos != null && workBos.size() > 1) {
                workAgos = workBos.subList(1, workBos.size());
                workListAdapter.setNewData(workAgos);

                workListAdapter.setOnItemChildClickListener(new BaseQuickAdapter.OnItemChildClickListener() {
                    @Override
                    public void onItemChildClick(BaseQuickAdapter adapter, View view, int position) {
                        Intent intent = new Intent(AllCertificationActivity.this, UploadWorkActivity.class);
                        intent.putExtra("work_id", workAgos.get(position).getId());
                        intent.putExtra("works_imgs", (Serializable) workAgos.get(position).getImg());
                        intent.putExtra("isAll", true);
                        startActivity(intent);
                    }
                });
            } else {
                workListAdapter.setEmptyView(emptyTextView.getEmptyView("暂无工作经历"));
                workListAdapter.setNewData(null);
            }
        }
        mViewUploadEdu.setVisibility(View.GONE);

    }

    @Override
    public void showEduListSuccess(List<EducationBo> educationBos) {
        mEducationBos = educationBos;
        if (mType == 3) {
            if (educationBos != null && educationBos.size() > 0) {
                mViewUploadEdu.setVisibility(View.GONE);
                mViewEducation.setVisibility(View.VISIBLE);

                if (educationBos != null && !educationBos.isEmpty()) {
                    showEducationSuccess(educationBos.get(0));
                }
                EmptyTextView emptyTextView = new EmptyTextView(mRvEducationListAgo);
                EduInfoAdpter eduInfoAdpter = new EduInfoAdpter();
                eduInfoAdpter.bindToRecyclerView(mRvEducationListAgo);
                if (educationBos != null && educationBos.size() > 1) {
                    educationAgoBos = educationBos.subList(1, educationBos.size());
                    eduInfoAdpter.setNewData(educationAgoBos);
                    eduInfoAdpter.setOnItemChildClickListener(new BaseQuickAdapter.OnItemChildClickListener() {
                        @Override
                        public void onItemChildClick(BaseQuickAdapter adapter, View view, int position) {
                            Intent intent = new Intent(AllCertificationActivity.this, UploadEduActivity.class);
                            intent.putExtra("edu_id", educationAgoBos.get(position).getId());
                            intent.putExtra("edu_imgs", educationAgoBos.get(position));
                            intent.putExtra("isAll", true);
                            startActivity(intent);
                        }
                    });
                } else {
                    eduInfoAdpter.setEmptyView(emptyTextView.getEmptyView("暂无教育经历"));
                    eduInfoAdpter.setNewData(null);
                }
            } else {
                mViewUploadEdu.setVisibility(View.VISIBLE);
                mViewEducation.setVisibility(View.GONE);
            }
        }
        mViewUploadWork.setVisibility(View.GONE);
    }

    @Override
    public void showUploadAuthenticationImageSuccess() {
        mRgCeritifcation.check(R.id.rb_ceritifcation_career);
    }

    private void showUserInfo(UserCardBo s) {
        if (s == null) return;
        if (mLabelList != null) {
            mLabelList = new ArrayList<>(s.getClassify());
        }
        AM.image().bindToCircleObject(s.getUserHead(), mIvUserHead);
        mEdtUserName.setText(TextUtils.isEmpty(s.getUserName()) ? "" : s.getUserName());
        mEdtUserIndustry.setText(TextUtils.isEmpty(s.getUserIndustry()) ? "" : s.getUserIndustry());
        mTvUserBiaoqian.setText((s.getClassify() != null && s.getClassify().size() > 0
                ? DataServer.getClassfiyStr2(s.getClassify()) : ""));
        mTvUserCity.setText(TextUtils.isEmpty(s.getUserWorkAddress()) ? "" : s.getUserWorkAddress());
        mTvUserAddress.setText(TextUtils.isEmpty(s.getUserDetailAddress()) ? "" : s.getUserDetailAddress());
        mTvUserMobile.setText(TextUtils.isEmpty(s.getPhone()) ? "" : s.getPhone());
        mTvUserEmail.setText(TextUtils.isEmpty(s.getUserEmail()) ? "" : s.getUserEmail());
        mTvUserWechat.setText(TextUtils.isEmpty(s.getWeChatId()) ? "" : s.getWeChatId());
        mTvUserCardNumber.setText(TextUtils.isEmpty(s.getUserCardId()) ? "" : s.getUserCardId());
        AM.image().bindToCard(s.getUserCardUrl(), mIvUserCard);
        mViewUploadWork.setVisibility(View.GONE);
        mViewUploadEdu.setVisibility(View.GONE);
    }

    private void initGallery(int pos) {
        PictureSelector.create(this)
                .openGallery(PictureMimeType.ofImage())
                .theme(R.style.picture_default_style1)
                .selectionMode(PictureConfig.SINGLE)// 多选 or 单选
                .previewImage(true)// 是否可预览图片
                .isZoomAnim(true)// 图片列表点击 缩放效果 默认true
                .isCamera(true)
                .enableCrop(true)// 是否裁剪
                .circleDimmedLayer(true)// 是否圆形裁剪 true or false
                .withAspectRatio(1, 1)// int 裁剪比例 如16:9 3:2 3:4 1:1 可自定义
                .compress(true)// 是否压缩
                .hideBottomControls(false)// 是否显示uCrop工具栏，默认不显示
                .isGif(false)// 是否显示gif图片
                .freeStyleCropEnabled(true)// 裁剪框是否可拖拽
                .circleDimmedLayer(true)// 是否圆形裁剪
                .selectionMedia(selectList)// 是否传入已选图片
                .scaleEnabled(true)
                .forResult(pos);//结果回调onActivityResult code
    }


    private void showPickerView() {// 弹出选择器

        OptionsPickerView pvOptions = new OptionsPickerBuilder(this, new OnOptionsSelectListener() {
            @Override
            public void onOptionsSelect(int options1, int options2, int options3, View v) {
                //返回的分别是三个级别的选中位置
                String tx = options1Items.get(options1).getPickerViewText() +
                        options2Items.get(options1).get(options2);
                mTvUserCity.setText(tx);

            }
        })

                .setTitleText("城市选择")
                .setDividerColor(R.color.div_primary)
                .setLineSpacingMultiplier(2.5f)
                .setTextColorCenter(R.color.text_primary) //设置选中项文字颜色
                .setContentTextSize(15)
                .build();


        pvOptions.setPicker(options1Items, options2Items);//三级选择器
        pvOptions.show();
    }

    private void initJsonData() {//解析数据

        /**
         * 注意：assets 目录下的Json文件仅供参考，实际使用可自行替换文件
         * 关键逻辑在于循环体
         *
         * */
        String JsonData = new GetJsonDataUtil().getJson(this, "province.json");//获取assets目录下的json文件数据

        List<JsonBean> jsonBean = parseData(JsonData);//用Gson 转成实体


        /**
         * 添加省份数据
         *
         * 注意：如果是添加的JavaBean实体，则实体类需要实现 IPickerViewData 接口，
         * PickerView会通过getPickerViewText方法获取字符串显示出来。
         */
        options1Items = jsonBean;

        for (int i = 0; i < jsonBean.size(); i++) {//遍历省份
            List<String> CityList = new ArrayList<>();//该省的城市列表（第二级）
            List<List<String>> Province_AreaList = new ArrayList<>();//该省的所有地区列表（第三极）

            for (int c = 0; c < jsonBean.get(i).getCityList().size(); c++) {//遍历该省份的所有城市
                String CityName = jsonBean.get(i).getCityList().get(c).getName();
                CityList.add(CityName);//添加城市
                List<String> City_AreaList = new ArrayList<>();//该城市的所有地区列表

                //如果无地区数据，建议添加空字符串，防止数据为null 导致三个选项长度不匹配造成崩溃
                if (jsonBean.get(i).getCityList().get(c).getArea() == null
                        || jsonBean.get(i).getCityList().get(c).getArea().size() == 0) {
                    City_AreaList.add("");
                } else {
                    City_AreaList.addAll(jsonBean.get(i).getCityList().get(c).getArea());
                }
                Province_AreaList.add(City_AreaList);//添加该省所有地区数据
            }

            /**
             * 添加城市数据
             */
            options2Items.add(CityList);

            /**
             * 添加地区数据
             */
            options3Items.add(Province_AreaList);
        }

        mHandler.sendEmptyMessage(MSG_LOAD_SUCCESS);

    }


    public List<JsonBean> parseData(String result) {//Gson 解析
        List<JsonBean> detail = new ArrayList<>();
        try {
            JSONArray data = new JSONArray(result);
            Gson gson = new Gson();
            for (int i = 0; i < data.length(); i++) {
                JsonBean entity = gson.fromJson(data.optJSONObject(i).toString(), JsonBean.class);
                detail.add(entity);
            }
        } catch (Exception e) {
            e.printStackTrace();
            mHandler.sendEmptyMessage(MSG_LOAD_FAILED);
        }
        return detail;
    }


    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (mHandler != null) {
            mHandler.removeCallbacksAndMessages(null);
        }
    }
}
